/*
package com.linkoog.devtools.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

*/
/**
 * @author chenshu
 *//*

public class CommandHelper {


    public static int DEFAULT_TIMEOUT = 5000;
    public static final int DEFAULT_INTERVAL = 1000;

    public static CommandResult exec(String command) throws IOException, InterruptedException {
        Process process = Runtime.getRuntime().exec(command);
        CommandResult commandResult = wait(process);
        if (process != null) {
            process.destroy();
        }
        return commandResult;
    }

    private static boolean isOverTime() {
        return ;
    }

    private static CommandResult wait(Process process) throws InterruptedException, IOException {
        BufferedReader errorStreamReader = null;
        BufferedReader inputStreamReader = null;
        try {
            errorStreamReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
            inputStreamReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            long start = System.currentTimeMillis();
            boolean isFinished = false;
            while ( System.currentTimeMillis() - start <= DEFAULT_TIMEOUT && )


            for (; ; ) {

                if (isOverTime()) {
                    CommandResult result = new CommandResult();
                    result.setExitValue(CommandResult.EXIT_VALUE_TIMEOUT);
                    result.setOutput("Command process timeout");
                    return result;
                }

                if (isFinished) {
                    CommandResult result = new CommandResult();
                    result.setExitValue(process.waitFor());
                    if (errorStreamReader.ready()) {
                        StringBuilder buffer = new StringBuilder();
                        String line;
                        while ((line = errorStreamReader.readLine()) != null) {
                            buffer.append(line);
                        }
                        result.setError(buffer.toString());
                    }

                    //parse info
                    if (inputStreamReader.ready()) {
                        StringBuilder buffer = new StringBuilder();
                        String line;
                        while ((line = inputStreamReader.readLine()) != null) {
                            buffer.append(line);
                        }
                        result.setOutput(buffer.toString());
                    }
                    return result;
                }

                try {
                    isFinished = true;
                    process.exitValue();
                } catch (IllegalThreadStateException e) {
                    isFinished = false;
                    Thread.sleep(DEFAULT_INTERVAL);
                }
            }
        } finally {
            if (errorStreamReader != null) {
                try {
                    errorStreamReader.close();
                } catch (IOException e) {
                }
            }

            if (inputStreamReader != null) {
                try {
                    inputStreamReader.close();
                } catch (IOException e) {
                }
            }
        }
    }

    public static class CommandResult {

        public static final int EXIT_VALUE_TIMEOUT = -1;

        private String output;

        void setOutput(String error) {
            output = error;
        }

        String getOutput() {
            return output;
        }

        int exitValue;

        void setExitValue(int value) {
            exitValue = value;
        }

        int getExitValue() {
            return exitValue;
        }

        private String error;

        */
/**
         * @return the error
         *//*

        public String getError() {
            return error;
        }

        */
/**
         * @param error the error to set
         *//*

        public void setError(String error) {
            this.error = error;
        }
    }

}






*/
